import sys
sys.path.append('/Users/chengyanan/PycharmProjects/kuai8_appium')
from uitls.read_init import Read_Init
class GetByLocal:
    def __init__(self,driver):
        self.driver=driver
    def get_element(self,key):
        #username=id>com.yixia.quick8:id/vg
        read_init = Read_Init()
        local=read_init.get_value(key)
        if local!=None:
            by=local.split('>')[0]  #定位方式"id"
            local_by=local.split('>')[1]  #定位的元素名称
            try:
                if by=='id':
                    return self.driver.find_element_by_id(local_by)
                elif by=='classname':
                    return self.driver.find_element_by_class_name(local_by)
                else:
                    return self.driver.find_element_by_xpath(local_by)
            except:
                return None
        else:
            return None


if __name__ == '__main__':
    get_element=GetByLocal()
    get_element.get_element('username')